package com.vincent.music.kkmusicapi.http;

public class ApiCallback<T> {

    private int code;
    private T data;
    private String message;


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public ApiCallback(int code, String message, T data) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> ApiCallback success(T t) {
        return new ApiCallback(200, "请求成功", t);
    }

    public static <T> ApiCallback success(T t, String message) {
        return new ApiCallback(200, message, t);
    }

    public static ApiCallback error(String message) {
        return new ApiCallback(-2, message, null);
    }

    public static ApiCallback success() {
        return new ApiCallback(200, "请求成功", null);
    }

    public static ApiCallback defaultFailed() {
        return new ApiCallback(-1, "没有数据", null);
    }


    public static ApiCallback success(String message) {
        return new ApiCallback(200, message, null);
    }

    public static ApiCallback failed(String message) {
        return new ApiCallback(-1, message, null);
    }

    public static <T> ApiCallback failed(String message,T t ) {
        return new ApiCallback(-1, message, t);
    }

    public static ApiCallback failed(int code) {
        return new ApiCallback(code, "", null);
    }

    public static ApiCallback failed(int code, String message) {
        return new ApiCallback(code, message, null);
    }

    @Override
    public String toString() {
        return "ApiCallback{" +
                "code=" + code +
                ", data=" + data +
                ", message='" + message + '\'' +
                '}';
    }
}
